package com.example.crt_dispatching_center.controller;

import com.example.crt_dispatching_center.dto.LinePassengerFlowDTO;
import com.example.crt_dispatching_center.dto.StaPassengerLingerDTO;
import com.example.crt_dispatching_center.dto.TransferDTO;
import com.example.crt_dispatching_center.entity.Line;
import com.example.crt_dispatching_center.service.RealTimeDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rtd")
public class RealTimeDataController {

    @Autowired
    private RealTimeDataService realTimeDataService;

    @PostMapping("/lineFlow")
    public void receiveLinePassengerFlow(@RequestBody LinePassengerFlowDTO linePassengerFlowDTO) throws Exception {
        String lineName = linePassengerFlowDTO.getLineName();
        float flow = linePassengerFlowDTO.getPassengerFlow();
        Line line = new Line();
        line.setLine(lineName);
        line.setFlow(flow);

        realTimeDataService.processLinePassengerFlow(line);
    }

    @PostMapping("/staLinger")
    public void recStaLinger(@RequestBody StaPassengerLingerDTO staPassengerLingerDTO) throws Exception {
        realTimeDataService.processStaLinger(staPassengerLingerDTO);
    }

    @PostMapping("/transfer")
    public void recTransfer(@RequestBody TransferDTO transferDTO) throws Exception {
        realTimeDataService.processTransfer(transferDTO);
    }
}
